package com.suray.wcs.service.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.suray.commin.core.utils.StringUtils;
import com.suray.wcs.service.system.entity.ConnectConfDB;
import com.suray.wcs.service.system.mapper.ConnectConfMapper;
import com.suray.wcs.service.system.service.IConnectConfService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:库口配置服务实现
 * @author: rongbj
 * @date:2019年12月5日 下午7:52:57
 */
@Service
public class ConnectConfServiceImpl extends ServiceImpl<ConnectConfMapper, ConnectConfDB> implements IConnectConfService {
    /**
     * @param connectType
     * @return
     */
    @Override
    public List<ConnectConfDB> getConnectConfs(Integer connectType) {
        QueryWrapper<ConnectConfDB> queryWrapper = new QueryWrapper<ConnectConfDB>();
        queryWrapper.lambda().eq(ConnectConfDB::getConnectType, connectType);
        return list(queryWrapper);
    }

    @Override
    public List<ConnectConfDB> queryConnectConf(ConnectConfDB connectConfDB) {
        QueryWrapper<ConnectConfDB> queryWrapper = new QueryWrapper<ConnectConfDB>();
        if (StringUtils.isNotEmpty(connectConfDB.getConnectName())) {
            queryWrapper.lambda().like(ConnectConfDB::getConnectName, connectConfDB.getConnectName());
        }
        if (connectConfDB.getConnectType() != null) {
            queryWrapper.lambda().eq(ConnectConfDB::getConnectType, connectConfDB.getConnectType());
        }
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public void insertConnectConfDB(ConnectConfDB connectConfDB) {
        this.save(connectConfDB);
    }

    @Override
    public void updateConnectConfDB(ConnectConfDB connectConfDB) {
        this.updateById(connectConfDB);
    }

    /**
     * 通过接驳点ID获取
     *
     * @param connectId
     * @return
     */
    @Override
    public ConnectConfDB selectByConnectId(Long connectId) {
        return baseMapper.selectById(connectId);
    }

    @Override
    public List<ConnectConfDB> findByType(Integer connectType) {
        QueryWrapper<ConnectConfDB> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(ConnectConfDB::getConnectType, connectType).eq(ConnectConfDB::getConnectFlag, true);

        return list(queryWrapper);
    }
}
